#include "Flee.h"

Flee* Flee::pInst=NULL;


Flee::Flee()
{

}

Flee::~Flee()
{

}

Flee* Flee::GetInstance()
{
	if(pInst == NULL)
	{
		pInst = new Flee();
	}

	return pInst;

}

void Flee::Enter(AbstractEnemy* pEnemy)
{
	//set fleeing behaviour on
	pEnemy->GetBehaviours()->SetFleeOn(true);

	//set target to player
	pEnemy->GetBehaviours()->SetTargetPosition(pEnemy->GetPlayerPos());
}

void Flee::Execute(AbstractEnemy* pEnemy)
{
	//get new velocities from behaviours
	XMFLOAT3 velocity1 = pEnemy->GetVelocity();
	XMFLOAT3 velocity2 = pEnemy->GetBehaviours()->AccumulateBehaviours();

	//add velocities
	velocity1.x += velocity2.x;
	velocity1.z += velocity2.z;

	//set new velocity
	pEnemy->SetVelocity(velocity1);
}

void Flee::Exit(AbstractEnemy* pEnemy)
{
	//turn fleeing off
	pEnemy->GetBehaviours()->SetFleeOn(true);
}

void Flee::Release()		// Static
{

	if(pInst)
	{
		delete pInst;
		pInst = NULL;
	}
}
